package com.turing.post.report.util;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Table;

import com.turing.post.util.PCPSUtil;

/**
 * 帐户子系统机构卡种类日结表
 * 
 * @author yxb
 * 
 */
@SuppressWarnings("serial")
@Entity
@Table(name = "AccSysBranchCardDaySett")
@IdClass(AccSysBranchCardDaySett.class)
public class AccSysBranchCardDaySett implements Serializable {

	public AccSysBranchCardDaySett() {
		super();
	}

	/**
	 * 发卡商NO
	 */
	private String issueCompanyNo = null;

	@Id
	@Column(name = "IssueCompanyNo", nullable = false)
	public String getIssueCompanyNo() {
		return this.issueCompanyNo;
	}

	public void setIssueCompanyNo(String issueCompanyNo) {
		this.issueCompanyNo = issueCompanyNo;
	}

	/**
	 *帐务日期
	 */
	private Date tranDate = null;

	@Id
	@Column(name = "TranDate", nullable = false)
	public Date getTranDate() {
		return this.tranDate;
	}

	public void setTranDate(Date tranDate) {
		this.tranDate = tranDate;
	}

	/**
	 * 销售机构号
	 */
	private String saleBranchNo = null;

	@Id
	@Column(name = "SaleBranchNo", nullable = false)
	public String getSaleBranchNo() {
		return this.saleBranchNo;
	}

	public void setSaleBranchNo(String saleBranchNo) {
		this.saleBranchNo = saleBranchNo;
	}

	/**
	 * 卡种类
	 */
	private BigInteger cardClassicId = null;

	@Id
	@Column(name = "CardClassicId", nullable = false)
	public BigInteger getCardClassicId() {
		return this.cardClassicId;
	}

	public void setCardClassicId(BigInteger cardClassicId) {
		this.cardClassicId = cardClassicId;
	}

	/**
	 * 上日余额
	 */
	private BigInteger lastBalance = null;

	@Column(name = "LastBalance", nullable = false)
	public BigInteger getLastBalance() {
		return this.lastBalance;
	}

	public void setLastBalance(BigInteger lastBalance) {
		this.lastBalance = lastBalance;
	}

	/**
	 * 本日销售
	 */
	private BigInteger saleAmount = null;

	@Column(name = "SaleAmount", nullable = true)
	public BigInteger getSaleAmount() {
		return this.saleAmount;
	}

	public void setSaleAmount(BigInteger saleAmount) {
		this.saleAmount = saleAmount;
	}

	/**
	 * 本日充值
	 */
	private BigInteger depositAmount = null;

	@Column(name = "DepositAmount", nullable = false)
	public BigInteger getDepositAmount() {
		return this.depositAmount;
	}

	public void setDepositAmount(BigInteger depositAmount) {
		this.depositAmount = depositAmount;
	}

	/**
	 * 本日消费
	 */
	private BigInteger consumeAmount = null;

	@Column(name = "ConsumeAmount", nullable = false)
	public BigInteger getConsumeAmount() {
		return this.consumeAmount;
	}

	public void setConsumeAmount(BigInteger consumeAmount) {
		this.consumeAmount = consumeAmount;
	}

	/**
	 * 本日赎回
	 */
	private BigInteger redemingAmount = null;

	@Column(name = "RedemingAmount", nullable = false)
	public BigInteger getRedemingAmount() {
		return this.redemingAmount;
	}

	public void setRedemingAmount(BigInteger redemingAmount) {
		this.redemingAmount = redemingAmount;
	}

	/**
	 * 本日扣手续费
	 */
	private BigInteger feeAmount = null;

	@Column(name = "FeeAmount", nullable = false)
	public BigInteger getFeeAmount() {
		return this.feeAmount;
	}

	public void setFeeAmount(BigInteger feeAmount) {
		this.feeAmount = feeAmount;
	}

	/**
	 * 本日调整
	 */
	private BigInteger adjustAmount = null;

	@Column(name = "AdjustAmount", nullable = false)
	public BigInteger getAdjustAmount() {
		return this.adjustAmount;
	}

	public void setAdjustAmount(BigInteger adjustAmount) {
		this.adjustAmount = adjustAmount;
	}

	/**
	 * 本日余额
	 */
	private BigInteger Balance = null;

	@Column(name = "Balance", nullable = false)
	public BigInteger getBalance() {
		return this.Balance;
	}

	public void setBalance(BigInteger balance) {
		this.Balance = balance;
	}

	/**
	 * 重新计算本日余额
	 */
	public void reCalcBalance() {
		BigInteger bal = getLastBalance();
		bal = bal.add(getSaleAmount());
		bal = bal.add(getDepositAmount());
		bal = bal.subtract(getConsumeAmount());
		bal = bal.subtract(getRedemingAmount());
		bal = bal.subtract(getFeeAmount());
		bal = bal.add(getAdjustAmount());
		setBalance(bal);
	}

	@Override
	public int hashCode() {
		return PCPSUtil.getObjectListHashCode(new Object[] {
				getIssueCompanyNo(), getTranDate(), getSaleBranchNo(),
				getCardClassicId() });
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof AccSysBranchCardDaySett))
			return false;

		AccSysBranchCardDaySett other = (AccSysBranchCardDaySett) obj;

		if (!PCPSUtil.compareObject(this.getIssueCompanyNo(), other
				.getIssueCompanyNo()))
			return false;

		if (!PCPSUtil.compareObject(this.getTranDate(), other.getTranDate()))
			return false;

		if (!PCPSUtil.compareObject(this.getSaleBranchNo(), other
				.getSaleBranchNo()))
			return false;

		return PCPSUtil.compareObject(this.getCardClassicId(), other
				.getCardClassicId());
	}
}
